package springboot.springboot06.Controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Slf4j
@Controller
public class formcontroller {

    @GetMapping("/form_layouts")
    public String formcontrol(){
        return "form/form_layouts";
    }

    @PostMapping("/upload")
    public String upload(String email, String username, MultipartFile headimg, MultipartFile[] photos) throws IOException {

        log.info("上传的信息：email={},username={},headimg={},photos={}",
                email,username,headimg.getSize(),photos.length);

        if(!headimg.isEmpty()){
            String originalFilename = headimg.getOriginalFilename();
            headimg.transferTo(new File("D:\\cache\\"+originalFilename));
        }
        if(photos.length>0){
            for(MultipartFile photo : photos){
                String originalFilename = photo.getOriginalFilename();
                photo.transferTo(new File("D:\\cache\\"+originalFilename));
            }
        }


        return "main";
    }

}
